<?php 
include_once('../Utilities/connect.php');
mysql_set_charset('utf8',getConnect());
function insertUser ( $email, $pass, $cusId)
{
  $sql="insert into user (UserName, Password, Email, RoleID, CustomerID) values ('$email','$pass','$email', '3', '$cusId')";
  mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
}
function insertOrder($createdate, $toAdd, $toName, $des, $paymentId, $total, $cusId)
{
	$sql="insert into orders (CreatedDate, toAddress, toName, DescriptionOther,Status,PaymentID,Total, CustomerID) values ('$createdate','$toAdd','$toName','$des',0,'$paymentId','$total', '$cusId')";
  $rl=mysql_query($sql, getConnect());
	if($rl) echo 'success';
	else 'fails';
}
function inserOrderDetail($prid, $orid, $qty, $amo)
{
	$sql="insert into orderdetail (ProductID, OrderID, Quantity , Amount) values ('$prid','$orid','$qty', '$amo')";
  mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
}
function insertCustomer ($name, $addr, $email, $phone)
{
	$sql="insert into customer (CustomerName , Address, Email, HomePhone) values ('$name','$addr','$email','$phone')";
	$rl=  mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
	
}
function getOrderId($cusId)
{
	$sql="select * from orders where CustomerID='$cusId' order by OrderID desc limit 0,1";
	$rl=mysql_query($sql,getConnect()) or die (mysql_error(getConnect()));
	if($rl!=null)
	{
		$or=mysql_fetch_row($rl);
	}
 	return $or;
}
function getCustomerById($id)
{
  $sql="select * from customer where CustomerID='$id'";
  $rl=mysql_query($sql,getConnect()) or die (mysql_error(getConnect()));
	if($rl!=null)
	{
		$or=mysql_fetch_row($rl);
	}
 	return $or;
}
function updateUser($cusId,$userId)
{
  $sql="Update user set CustomerID='$cusId' where UserID='$userId' ";
   $rl=mysql_query($sql,getConnect()) or die (mysql_error(getConnect()));
}
function getCustomerId($email)
{
	$sql="select * from customer where Email='$email' order by CustomerID desc limit 0,1";
	$rl=mysql_query($sql,getConnect()) or die (mysql_error(getConnect()));
	if($rl!=null)
	{
		$or=mysql_fetch_row($rl);
	}
 	return $or;
}
function getPaymentMethod()
{
 $sql ='select * from paymentmethod';
 $rl=mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
 $arr=array();
		if($rl!=null)
		{
			while ($pm = mysql_fetch_array($rl))
			{
				$arr[]=$pm;
			}
		}
		return $arr;
}
function getBank()
{
 $sql ='select * from bank';
 $rl=mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
 $arr=array();
		if($rl!=null)
		{
			while ($pm = mysql_fetch_array($rl))
			{
				$arr[]=$pm;
			}
		}
		return $arr;
}
function getMethodById($id)
{
  $sql ="select * from paymentmethod where PaymentID='$id' ";
 $rl=mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
 return $rl;
}
function getBankById($id)
{
	$sql ="select * from bank where BankID='$id'";
 $rl=mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
 return $rl;
}
function updateCustomer($cusId, $name, $addr, $email, $phone)
{
 $sql="update customer set CustomerName='$name', Address='$addr', Email='$email', HomePhone='$phone' where CustomerID='$cusId'";
  $rl=mysql_query($sql,getConnect()) or die (mysql_error(getConnect()));
  if($rl) echo 'success';
  else 'failse';
}
?>